package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	files := os.Args[1:]
	if len(files) == 0 {
		os.Exit(1)
	}
	for _, filename := range files {
		data, err := os.Open(filename)
		if err != nil {
			panic(err)
		}
		r := bufio.NewReader(data)
		for {
			// 读取结果返回string类型
			// lineBytes, err := r.ReadString('\n')
			// line := strings.TrimSpace(lineBytes)

			// 读取的结果返回 byte类型切片，需要强转为string类型后才可操作
			lineBytes, err := r.ReadBytes('\n')
			line := strings.TrimSpace(string(lineBytes))
			if err != nil && err != io.EOF {
				panic(err)
			}
			if err == io.EOF {
				break
			}
			fmt.Println(line)
		}
	}
}
